Skip to content

Fix #11538: Fix syntax error on C++23 'if consteval' / 'if !consteval' - #8733

Merged
danmar merged 1 commit into
cppcheck-opensource:mainfrom
autoantwort:feature/fix-if-consteval
Sep 6, 2026
Merged

Fix #11538: Fix syntax error on C++23 'if consteval' / 'if !consteval'#8733
danmar merged 1 commit into
cppcheck-opensource:mainfrom
autoantwort:feature/fix-if-consteval

Conversation

@autoantwort

Copy link
Copy Markdown
Contributor

The tokenizer only recognized if constexpr (...) and treated any other if <name> without parentheses as a syntax error, so C++23's if consteval { ... } and if !consteval { ... } were rejected.

Rewrite them to if ( __cppcheck_consteval__ ) { ... } and if ( ! __cppcheck_consteval__ ) { ... } respectively, using a synthetic unresolved symbol rather than a boolean literal so that valueflow can't treat the condition as always true/false.

@danmar danmar left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your suggested transformation seems valid to me. Feel free to finish this approach..

Comment thread lib/tokenize.cpp
The tokenizer only recognized 'if constexpr (...)' and treated any
other 'if <name>' without parentheses as a syntax error, so C++23's
'if consteval { ... }' and 'if !consteval { ... }' were rejected.

Rewrite them to 'if ( __cppcheck_consteval__ ) { ... }' and
'if ( ! __cppcheck_consteval__ ) { ... }' respectively, using a
synthetic unresolved symbol rather than a boolean literal so that
valueflow can't treat the condition as always true/false.
@autoantwort
autoantwort force-pushed the feature/fix-if-consteval branch from 2ebe4cc to e5b16e1 Compare August 10, 2026 16:37

@danmar danmar left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you insert parentheses but the links are not set. Is that done later?

@autoantwort

Copy link
Copy Markdown
Contributor Author

Later in the function createLinks(); gets called

@danmar
danmar merged commit b878dc2 into cppcheck-opensource:main Sep 6, 2026
71 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants